package com.example.kercar;

import Keriosity_bluetoothCommand.BluetoothCommand;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity {

	EditText nomConnexion = null; 
	private Button k_buttonConnexion = null;
	private Button k_buttonDroit = null;
	private Button k_buttonGauche = null;
	private Button k_buttonAvancer = null;
	private Button k_buttonReculer = null;
	private Button k_buttonArret = null;
	
	BluetoothCommand k_bluetooth;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_manuel);
		
		k_bluetooth = new BluetoothCommand();
		
		k_buttonConnexion = (Button) findViewById(R.id.connexion);
		k_buttonAvancer = (Button) findViewById(R.id.avancer);
		k_buttonReculer = (Button) findViewById(R.id.reculer);
		k_buttonArret = (Button) findViewById(R.id.arret);
		k_buttonDroit = (Button) findViewById(R.id.droite);
		k_buttonGauche = (Button) findViewById(R.id.gauche);		
		nomConnexion = (EditText)findViewById(R.id.nomConnexion);
				
		
		/** On definit les listeners des bouttons **/
		
		//boutton de connexion
        k_buttonConnexion.setOnClickListener(new OnClickListener() {
           	
        	public void onClick(View v) {
        		String nameKeriosity = nomConnexion.getText().toString();
        		//changer le nom "keriosity" selon le robot
        		if(k_bluetooth.find(nameKeriosity)) //si on trouve notre robot
        			k_bluetooth.connect(); //on se connect           
        	}
        }); //k_buttonConnexion
        
        
        		//bouttons de directions 
        
        k_buttonAvancer.setOnClickListener(new OnClickListener() {     	
        	public void onClick(View v) {k_bluetooth.send("z");}
        }); 
        
        
        k_buttonReculer.setOnClickListener(new OnClickListener() {           	
        	public void onClick(View v) {k_bluetooth.send("s");}
        }); 
        
        
        k_buttonArret.setOnClickListener(new OnClickListener() {           	
        	public void onClick(View v) {k_bluetooth.send("e");} 
        }); 
        
        k_buttonDroit.setOnClickListener(new OnClickListener() {           	
        	public void onClick(View v) {k_bluetooth.send("d");} 
        });
        
        k_buttonGauche.setOnClickListener(new OnClickListener() {           	
        	public void onClick(View v) {k_bluetooth.send("q");} 
        });
        
        
	}	
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
	

		
	

	
	
	
	
	
	
	
	

}
